package com.tamakloe.guestbook;

import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Text;


@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Greeting {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String userName;

    @Persistent
    private String userEmail;
    
    @Persistent
    private Text content;

    @Persistent
    private Date date;
    
    private String delimiter = ", ";

    public Greeting(String userName, String userEmail, String content, Date date) {
        this.userName = userName;
        this.userEmail = userEmail;
        this.content =  new Text(content);
        this.date = date;
    }
    
    public Greeting(){}

    public Long getId() {
        return id;
    }

    public String getUserName() {
        return userName;
    }
    
    public String getUserEmail() {
    	return userEmail;
    }

    public String getContent() {
    	if (content!= null){
    		return content.getValue();
    	}else{
    		return null;
    	}
    	
    }

    public Date getDate() {
        return date;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    public void setUserEmail(String userEmail){
    	this.userEmail = userEmail;
    }

    public void setContent(String content) {
        this.content = new Text(content);
    }

    public void setDate(Date date) {
        this.date = date;
    }
    public String getFormatedDate(){
    	SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    	return sdf.format(date);
    }
    public String getDataInCSV(){
    	delimiter = ",";
    	return this.id.toString() + delimiter + this.getFormatedDate() + delimiter + this.userName + delimiter+ this.userEmail + delimiter + "\"" + this.content.getValue() + "\"\n";
    }
}
